﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Summer.IService;
using Summer.Model.Attribute;
using Summer.WebApi.Filter;
using Summer.WebApi.Helper;

namespace Summer.WebApi.Api
{
    /// <summary>
    /// 测试控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class TestController : ControllerBase
    {
        private ITestService _test;
        public TestController(ITestService testService)
        {
            _test = testService;
        }

        /// <summary>
        /// 测试获取数据
        /// </summary>
        /// <returns></returns>
        [HttpGet][Authorize(Policy = "testpolly")]
        public string Get()
        {
            //throw new ExecuteException();
            return _test.Get();
        }       

        /// <summary>
        /// 测试获取名称
        /// </summary>
        /// <param name="name">名称</param>
        /// <returns></returns>
        [HttpGet]
        //[Authorize]
        public virtual async Task<string> GetName(string name)
        {
            //throw new ExecuteException();
            return _test.GetName(name);
        }

        //[AllowAnonymous]
        public void TestHttpClient()
        {
            HttpClient client = new HttpClient();
            //client.DefaultRequestHeaders.Authorization 
            client.DefaultRequestHeaders.Add("Authorization", "Bearer ");
        }
    }
}